home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
program
/
386
/
algrtest
/
multiply.s
< prev
next >
Wrap
Text File
|
1985-11-19
|
5KB
|
128 lines
; Program Name: MULTIPLY.S
; Version: 1.003
; Assembly Instructions:
; Assemble in PC-relative mode and save with a TOS extension.
; Execution Instructions:
; Execute from the desktop; or execute SPAWN.TTP, type MULTIPLY.TOS on
; its command line and view this program's output in MULTIPLY.DAT.
; Program Function:
; Measures the speed of multiplication algorithms.
calculate_program_size:
lea -$102(pc), a1 ; Fetch basepage start address.
lea program_end, a0 ; Fetch program end address.
trap #6 ; Return unused memory to op system.
print_heading:
lea heading, a0
bsr print_string
the_mulu_instruction:
lea header_1, a0
bsr print_string
move.l #49999, d7 ; D7 is counter for the loop.
trap #3 ; Fetch start time.
move.l d0, d3 ; Save start_time in D3.
mulu_loop: ; Marks start of instruction in the loop.
mulu #5, d0 ; Instruction in the loop.
memory_1: ; Marks end of instruction in the loop.
dbra d7, mulu_loop ; Loop 50000 times.
trap #3 ; Fetch end time.
sub.l d3, d0 ; Subtract start time from end time.
trap #10 ; Convert to decimal milliseconds and print.
addition:
lea header_2, a0
bsr.s print_string
move.l #49999, d7 ; D7 is counter for the push loop.
trap #3 ; Fetch start time.
move.l d0, d3 ; Save start_time in D3.
addition_loop: ; Marks start of instruction in the loop.
move.l d0, d2 ; To add one.
add.l d0, d0 ; To double to two.
add.l d0, d0 ; To double to four.
add.l d2, d0 ; To complete multiplication by 5.
memory_2: ; Marks end of instruction in the loop.
dbra d7, addition_loop ; Loop 50000 times.
trap #3 ; Fetch end time.
sub.l d3, d0 ; Subtract start time from end time.
trap #10 ; Convert to decimal milliseconds and print.
shift_and_add:
lea header_3, a0
bsr.s print_string
move.l #49999, d7 ; D7 is counter for the push loop.
trap #3 ; Fetch start time.
move.l d0, d3 ; Save start_time in D3.
shift_loop: ; Marks start of instruction in the loop.
move.l d0, d2 ; Save a copy to add.
asl.l #2, d0 ; Shift to multiply by 4.
add.l d2, d0 ; To complete multiplication by 5.
memory_3: ; Marks end of instruction in the loop.
dbra d7, shift_loop ; Loop 50000 times.
trap #3 ; Fetch end time.
sub.l d3, d0 ; Subtract start time from end time.
trap #10 ; Convert to decimal milliseconds and print.
print__mulu_requisite_memory:
lea header_4, a0
bsr.s print_string
lea memory_1, a0 ; Calculate number of bytes occupied by the
lea mulu_loop, a1 ; instruction in the loop.
bsr.s print_requisite_memory
print_addition_requisite_memory:
lea header_5, a0
bsr.s print_string
lea memory_2, a0 ; Calculate number of bytes occupied by the
lea addition_loop, a1 ; instruction in the loop.
bsr.s print_requisite_memory
print_shift_and_add_requisite_memory:
lea header_6, a0
bsr.s print_string
lea memory_3, a0 ; Calculate number of bytes occupied by the
lea shift_loop, a1 ; instruction in the loop.
bsr.s print_requisite_memory
terminate:
trap #8
; SUBROUTINES
print_requisite_memory:
suba.l a1, a0
move.l a0, d1
trap #4 ; Returns address of decimal string in A0.
bsr.s print_string
lea header_7, a0
bsr.s print_string
rts
print_string: ; Expects address of string to be in A0.
pea (a0) ; Push address of string onto stack.
move.w #9, -(sp) ; Function = c_conws = GEMDOS $9.
trap #1 ; GEMDOS call
addq.l #6, sp ; Reset stack pointer to top of stack.
rts
data
heading: dc.b "MULTIPLY Execution Results",$D,$A,$D,$A,0
header_1: dc.b " MULU time: ",0
header_2: dc.b " Addition time: ",0
header_3: dc.b " Shift and add time: ",0
header_4: dc.b $D,$A," MULU requisite memory: ",0
header_5: dc.b " Addition requisite memory: ",0
header_6: dc.b " Shift and add requisite memory: ",0
header_7: dc.b " bytes",$D,$A,0
bss
align
program_end: ds.l 0
end